/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package supportlearning.session;

import java.util.Date;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import supportlearning.entities.Faq;

/**
 *
 * @author Huy
 */
@Stateless
public class managefaqs implements managefaqsLocal {
    @PersistenceContext(unitName = "eprojectSupportLearning-ejbPU")
    private EntityManager em;
  public boolean CreateFAQs(String FQuestions, String FAnswer, Date FDate) {
        Faq f = new Faq();
        f.setFaqQuestion(FQuestions);
        f.setFaqAnswer(FAnswer);
        f.setFaqDate(FDate);
        em.persist(f);
        return true;
    }

    public boolean EditFAQs(int id, String FQuestions, String FAnswer, Date FDate) {
        Faq f = em.find(Faq.class, id);
        if (f != null) {
            f.setFaqQuestion(FQuestions);
            f.setFaqAnswer(FAnswer);
            f.setFaqDate(FDate);
            em.persist(f);
            return true;
        } else {
            return false;//ID co van de`.
        }
    }

    public boolean DeleteFAQs(int id) {
        Faq f = em.find(Faq.class, id);
        em.remove(f);
        return true;
    }
    public void persist(Object object) {
        em.persist(object);
    }

    public void persist1(Object object) {
        em.persist(object);
    }

}
